package com.a.lib_network.http

import android.app.Activity
import android.content.Context
import com.hjq.http.listener.OnHttpListener
import com.a.lib_utils.TipUtil.delayDismiss
import com.a.lib_utils.TipUtil.failTip
import com.a.lib_utils.TipUtil.loadingTip
import okhttp3.Call

/**
 * 只适用于在activity
 * */
@Deprecated("不要在Activity进行请求，会造成Activity臃肿，现改为用LiveDataHttpCallBack", ReplaceWith("LiveDataHttpCallBack()"))
abstract class SimpleCallBack<T>(context: Activity) : OnHttpListener<T> {
    private val context: Context
    abstract fun succeed(result: T)

    override fun onStart(call: Call?) {
        super.onStart(call)
        loadingTip(context, "正在加载")
    }

    override fun onSucceed(result: T, cache: Boolean) {
        super.onSucceed(result, cache)
    }

    override fun onSucceed(result: T) {
        succeed(result)
    }

    override fun onFail(e: Exception) {
        failTip(context, e.toString())
    }

    override fun onEnd(call: Call) {
        super.onEnd(call)
        delayDismiss(700)
    }

    init {
        this.context = context
    }
}
